#ifndef QQ_RTC_VIDEO_ENGINE_BY_AGORA
#define QQ_RTC_VIDEO_ENGINE_BY_AGORA

#include <qobject.h>
#include <qpainter.h>
#include <qwidget.h>
#include <qimage.h>
#include <qdebug.h>

#include <high_level_api/IAgoraRtcEngine.h>
#include <high_level_api/IAgoraMediaEngine.h>

#ifdef Q_OS_WIN
#include <Windows.h>
#include <dwmapi.h>
#include <windowsx.h>
#else Q_OS_LIUNX
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <QX11Info>
#endif

#define WM_MSGID(code)				(WM_USER+0x200+code)
#define EID_JOIN_CHANNEL_SUCCESS	0x00000002
#define EID_USER_JOINED				0x00000004
#define EID_USER_OFFLINE			0x00000004

#include "QQRTCVideoEngine.h"

#define APP_ID "afe77c6bc7e844e688dd1ceb47343144"
#define APP_CERTIFICATE "451a340d3725453583010fc4dd7319d8"
#define APP_TOKEN "007eJxTYFj1vnMVr6nk9j12KelaFbcunZ+tcF5kwYbF77zZZ5+6/lJNgSExLdXcPNksKdk81cLEJNXMwiIlxTA5NcnE3NjE2NDEZF7a7PSGQEYGHeaPzIwMEAjiszEYGhmbmJoxMAAA9wwgKQ=="


class QQRTCIVideoFrameObserver :public QObject, public agora::media::IVideoFrameObserver
{
	Q_OBJECT
public:
	virtual agora::media::IVideoFrameObserver::VIDEO_FRAME_PROCESS_MODE getVideoFrameProcessMode() override;

	virtual agora::media::base::VIDEO_PIXEL_FORMAT getVideoFormatPreference() override;

	virtual bool onCaptureVideoFrame(agora::rtc::VIDEO_SOURCE_TYPE sourceType, VideoFrame& videoFrame) override;

	virtual bool onPreEncodeVideoFrame(agora::rtc::VIDEO_SOURCE_TYPE sourceType, VideoFrame& videoFrame) override;

	virtual bool onMediaPlayerVideoFrame(VideoFrame& videoFrame, int mediaPlayerId) override;

	virtual bool onRenderVideoFrame(const char* channelId, agora::rtc::uid_t remoteUid, VideoFrame& videoFrame) override;

	virtual bool onTranscodedVideoFrame(VideoFrame& videoFrame) override;
signals:
	void updateVideoFrame(const QPixmap& pixmap);
};

class QQRTCVideoEngineByAgora : public QQRTCVideoEngine
{
	Q_OBJECT
public:
	QQRTCVideoEngineByAgora(QObject* parent = nullptr);
	~QQRTCVideoEngineByAgora();
	/*
	 * @param info
	 * @brief This parameter requires three key-value pairs: account, channel, and token.
	 */
	virtual void startRealCommunicateVideo(const QVariantMap& info) override;

	/*
	 * @param info
	 * @brief This parameter requires three key-value pairs: account, channel, and token.
	 */
	virtual void stopRealCommunicateVideo(const QVariantMap& info) override;

private:
	agora::rtc::IRtcEngineEventHandler* mEventHandler;
	QQRTCIVideoFrameObserver* mVideoFrameObserver;
	agora::util::AutoPtr<agora::media::IMediaEngine> mMediaEngine;
	agora::rtc::IRtcEngine* mRtcEngine;
	bool mInitialize = false;
};

#endif // !QQ_RTC_VIDEO_ENGINE_BY_AGORA